/*
 * 作者: 黄伟
 * 时间: 2017-08-16
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {
	require("jquery");
	var appInfo = require('app/AppInfo');
	var c = require('app/utils/CommonUtils');
	var hc = require('app/utils/HttpClientUtils');
	var APIUtils = require('app/utils/APIUtils');
	var UserInfoUtils = require('app/utils/UserInfoUtils');
  var param = api.pageParam;
	var win = window;

	var action = {};
  var opt={};
//  opt.unionid=api.pageParam.unionid;
  opt.roomuuid=api.pageParam.roomuuid;
	action.wxPay1=function(money){
    opt.money = money;
    //opt.serverbase = "http://www.haojs.com.cn/node4";
    //var url = appInfo.serverbase+"/weixin/pay_orderinfo";
		opt.unionid=UserInfoUtils.getLoginedUser().userid;
		//opt.roomuuid=$(this).data("uuid");
		//opt.roomuuid = opt.roomuuid;
    var url = appInfo.serverbase + "/weixin/pay_orderinfo_haojs";
    var body={
      fee:opt.money,
      unionid:opt.unionid,
      roomuuid:opt.roomuuid
    };
		console.log(opt.unionid);
		console.log(opt.roomuuid);

    var notifyUrl = appInfo.serverbase + '/mvc/weixinpay/haojs/notify';
    hc.post(url,body,function(resp){
      var info = resp.result;
      var wxPay = api.require("wxPay");

					 wxPay.config({
						 apiKey: info.apikey,//
							 mchId: info.mchId,//
							 partnerKey: info.partnerKey,//
							 notifyUrl: notifyUrl,//
					 }, function(ret, err) {

							 if (ret.status) {
								 wxPay.pay({
									 description: info.des,//'捐赠给直播上科大App',
									 totalFee: opt.money,
									 tradeNo: info.tradeNo,//'1217752501201407033233368018',
									 detail: info.detail,//'iPad mini 16G 白色',
									 attach: info.attach,//'说明',
									 feeType: info.feeType,//'CNY',
									 timeStart: info.timeStart,//'20091225091010',
									 timeExpire: info.timeExpire,//'20091227091010',
									 productId: info.productId,//'12235413214070356458058',
							 }, function(ret, err) {
								 hjs.debug(ret);
								 hjs.debug(err);
								 if(ret.status){

									 api.alert({
										 title: '感谢您对我们的支持',
										 msg: '我们会不断进步完善，更好的为您服务！'
																	},function(ret,err){
																	 //coding...
																	});
									 closeFrm();
								 }

							 });
							 }
					 });

    });
  }
	return action;
});
